<template>
  <!-- 左侧按钮组 -->
  <el-button-group size="small">
    <el-button
      v-if="tableBtnGroupStatus.add"
      style="color: #00cd00"
      icon="circle-plus"
      @click="
        setSubmitFunctionType('insert');
        setFormInitValue({});
        changeSubmitFormDialogVisible();
      "
      >新增</el-button
    >
    <el-button
      v-if="tableBtnGroupStatus.refresh"
      style="color: #409eff"
      icon="RefreshRight"
      @click="refreshData()"
      >刷新</el-button
    >
    <el-button
      v-if="tableBtnGroupStatus.delete"
      style="color: #b9c9c7"
      icon="Delete"
      @click="deleteRecord"
      :disabled="deleteDisable"
      >删除</el-button
    >
    <el-button
      v-if="tableBtnGroupStatus.batchImport"
      style="color: #b340ff"
      icon="UploadFilled"
      @click="changeUploadDialogVisible()"
      >批量导入</el-button
    >
    <el-button
      v-if="tableBtnGroupStatus.batchInvalid"
      style="color: #ff4040"
      icon="Failed"
      >批量作废</el-button
    >
    <slot name="table-tools-btn"></slot>
  </el-button-group>
</template>

<script lang="ts" setup>
import { inject } from "vue";

interface TableBtnGroup {
  add: boolean;
  delete: boolean;
  refresh: boolean;
  batchImport: boolean;
  batchInvalid: boolean;
  advancedSearch: boolean;
}

/**
 * 按钮的状态, 用于控制按钮是否显示.
 */
const tableBtnGroupStatus = {
  add: true,
  delete: true,
  refresh: true,
  batchImport: true,
  batchInvalid: true,
  advancedSearch: true,
} as TableBtnGroup;

/**
 * 控制新增/编辑窗口的显示
 */
const changeSubmitFormDialogVisible = inject(
  "changeSubmitFormDialogVisible"
) as () => void;

/**
 * 设置打开的submitDialog窗口为新增窗口
 */
const setSubmitFunctionType = inject("setSubmitFunctionType") as (
  type: string
) => void;

/**
 * 控制上传窗口的显示
 */
const changeUploadDialogVisible = inject(
  "changeUploadDialogVisible"
) as () => void;

/**
 * 设置打开的窗口的数据的初始值
 */
const setFormInitValue = inject("setFormInitValue");

/**
 * 刷新数据
 */
const refreshData = inject("refreshData") as () => void;

/**
 * 删除按钮是否可点击
 */
const deleteDisable = inject("deleteDisable");

/**
 * 批量删除事件
 */
const deleteRecord = inject("deleteRecord");
</script>

<style scoped></style>
